using Api.Domain;
using Microsoft.EntityFrameworkCore;

var builder = WebApplication.CreateBuilder(args);

//添加MVC服务
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

//配置连接数据库
var connectionString = builder.Configuration.GetConnectionString("mysql");
builder.Services.AddDbContext<ApiDbContext>(x =>
{
    var serverVersion = new MySqlServerVersion(new Version(8, 0, 1));
    x.UseMySql(connectionString, serverVersion);
});

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

// 配置中间件
app.UseRouting();

app.MapControllers();

app.Run();